/**
 * Created by zhaocong on 2016/7/12.
 * 用户管理
 */
define(['jquery', 'timepicker'], function (require, exports, module) {
  "use strict";
  var cc = window.cc || {};
  cc.Customer = function () {
    var self = this;
    self.bindEvents = function () {
      /* 删除修改客户 */
      $('.checkboxes,#checkall').change(function () {
        var len = $('.checkboxes:checked').length;
        $('#custorEdit').prop('disabled', len != 1);
        $('#custorDel').prop('disabled', len < 1);
      });
      /* 点击高级搜索 */
      $('#advSearch').click(self.advSearch);
      /* 添加新的客户 */
      $('#custorAddBtn').click(self.custorAdd);
    };

    /**
     * 高级搜索
     */
    self.advSearch = function () {
      // var formData = {},
      //     form = document.getElementById('advSearchForm');
      // formData.custorType = form.elements['custorType'].value
      // formData.status = form.elements['status'].value
      // formData.citizenship = form.elements['citizenship'].value
      // formData.name = form.elements['name'].value
      // formData.sex = form.elements['sex'].value
      // formData.minAge = form.elements['minAge'].value
      // formData.maxAge = form.elements['maxAge'].value
      // formData.birthday = form.elements['birthday'].value
      // formData.cardType = form.elements['cardType'].value
      // formData.cardID = form.elements['cardID'].value
      // formData.tel = form.elements['tel'].value
      // $.ajax({
      //   url: '',
      //   type: 'get',
      //   data: formData,
      //   beforeSend: function () {
      //   },
      //   success: function (data) {
      //     $('#searchModal').modal('hide');
      //   },
      //   error: function () {
      //   }
      // });
    };

    /**
     * 添加新客户
     */
    self.custorAdd = function () {
      $('#custorAddModal').modal();
    };

    /**
     * 时间选择
     */
    self.datatime = function () {
      $('.form_datetime').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 4,
        forceParse: 0,
        showMeridian: 1,
        minView: 2,
        format: "yyyy-mm-dd"
      });
    };

    /**
     * 默认方法
     * @private
     */
    self._init = (function () {
      self.bindEvents();
      self.datatime();
      console.log('Customer is OK (づ￣3￣)づ');
    })();
  }

  module.exports = cc.Customer();
});